#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include "US.h"
#include "USS.h"

using namespace TOB;

/* This function return policy as int by login */
getUintResult* getuintbylogin_1_svc (getUintParameters *argp, struct svc_req *rqstp)
{
     US us;
     std::string login(argp->login);
     std::string field(argp->field);
     static getUintResult result;
     result.code = (int)us.getUintByLogin(login,field,(int&)result.result);
     return (&result);
};

/*This function get field by login*/
getResult* getstringbylogin_1_svc(getParameters *argp, struct svc_req *rqstp)
{
     US us;
     std::string login(argp->login);
     std::string field(argp->field);
     std::string value;

     static getResult result;
     result.code=(int)us.getStringByLogin(login,field,value);
     strcpy(result.result, value.c_str());
     return (&result);
};

/* This function verify login and return 1=if login non existence, 0=if login existence */
existenceResult* existencelogin_1_svc (existenceParameters *argp, struct svc_req *rqstp)
{
     US us;
     std::string login(argp->login);
     static existenceResult result;
     result.code = (int)us.existenceLogin(login,(int&)result.result);
     return (&result);
};

/* This function update field by login using value in type :"value" or "val1,val2"(winthout spaсes!) in field Policy */
updateResult* updatefieldbylogin_1_svc(updateParameters *argp, struct svc_req *rqstp)
{
     US us;  
     std::string login(argp->login);
     std::string field(argp->field);
     std::string value(argp->value);
     static updateResult result;
     result.code = (int)us.updateFieldByLogin(login, field, value);
     return (&result);                          
};

/* This function delete row by login  */
deleteResult* deleterowbylogin_1_svc(deleteParameters *argp, struct svc_req *rqstp)
{
     US us;
     std::string login(argp->login);
     static deleteResult result;
     result.code = (int)us.deleteRowByLogin(login);
     return (&result);                          
};

/* This function append row in DB */
appendResult* appendrow_1_svc(appendParameters *argp, struct svc_req *rqstp)
{
     US us;
     std::string login(argp->login);
     std::string password(argp->password);
     std::string role(argp->role);
     std::string policy(argp->policy);
     std::string name(argp->name);
     static appendResult result;
     result.code = (int)us.appendRow(login,password,role,policy,name);     
     return (&result);                           
};
